package com.cory.boot.support.jackson.format;

import java.io.IOException;
import org.apache.commons.lang3.StringUtils;
import com.cory.boot.component.uploader.UploaderUtils;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

public class ResourceSerialize extends JsonSerializer<String> {

	@Override
	public void serialize(String value, JsonGenerator jgen,
			SerializerProvider provider) throws IOException,
			JsonProcessingException {
		
		if (StringUtils.isNotBlank(value)) {
			value = UploaderUtils.getUrl(value);
		} 
		
		if (StringUtils.isBlank(value)) {
			jgen.writeString("");
		} else {
			jgen.writeString(value);
		}
			
	}
}
